require.config({
	paths:{
		  'backbone':'libs/backbone',
	    'underscore':'libs/underscore',
	    'jquery':'libs/jquery',
	    'text':'libs/text',
	    'css':'libs/css',
			'cookiejs':'libs/cookie',
			'homejs':'home/js/home',
			'homejx':'home/js/homejx',
			'categoryjx':'category/js/categoryjx',
			'shopjs':'shop/js/shop'
	}
});
require(['backbone'],function(Backbone){
	//配置路由条目，并设置回调函数
	var Router = Backbone.Router.extend({
		routes:{
			//配置路由条目
			'':'home',
			'home':'home',
			'category':'category',
			'shop':'shop',
			'mine':'mine'
		},
		home:function(){
			require(['cookiejs'],function(cookiejs){
				var tell = cookiejs.getCookie("tell");
				if(tell!=""){
					require(['jquery','cookiejs','text!./home/home.html','homejx','homejs','css!./home/css/home.css'],function($,cookiejs,html,homejx,homejs){
						$('#wrap').html(html);
						homejx.hjx();
						homejs.hjs();
					});
				}else{
					require(['jquery','text!./home/html/homenull.html','css!./home/css/homenull.css'],function($,htmlnull){
							$('#wrap').html(htmlnull);
					});
				}
			})
		},
		category:function(){
			require(['cookiejs'],function(cookiejs){
				var tell = cookiejs.getCookie("tell");
				if(tell!=""){
					require(['jquery','cookiejs','text!./category/category.html','categoryjx','css!./category/css/category.css'],function($,cookiejs,html,categoryjx){
						$('#wrap').html(html);
						categoryjx.cjx();
					});
				}else{
					require(['jquery','text!./category/html/categorynull.html','css!./category/css/categorynull.css'],function($,htmlnull){
							$('#wrap').html(htmlnull);
					});
				}
			})
		},
		shop:function(){
			require(['cookiejs'],function(cookiejs){
				var tell = cookiejs.getCookie("tell");
				if(tell!=""){
					require(['jquery','text!./shop/shop.html','shopjs','css!./shop/css/shop.css'],function($,html,shopjs){
							$('#wrap').html(html);
							shopjs.sjs();
					});
				}else{
					require(['jquery','cookiejs','text!./shop/html/shopnull.html','css!./shop/css/shopnull.css'],function($,cookiejs,htmlnull){
						$('#wrap').html(htmlnull);
						var $tell = $("#tell");
						var $pass = $("#pass");
						var $btn = $("#foot div");
						$btn.click(function(){
							cookiejs.setCookie('tell',$tell.val());
							cookiejs.setCookie('pass',$pass.val());
							require(['jquery','text!./shop/shop.html','shopjs','css!./shop/css/shop.css'],function($,html,shopjs){
									$('#wrap').html(html);
									shopjs.sjs();
							});
						})
					});
				}
			});
		},
		mine:function(){
			require(['cookiejs'],function(cookiejs){
				var tell = cookiejs.getCookie("tell");
				if(tell!=""){
					require(['jquery','cookiejs','text!./mine/mine.html','css!./mine/css/mine.css'],function($,cookiejs,html){
						$('#wrap').html(html);
						$btns = $('#footer p');
						$btns.click(function(){
							cookiejs.setCookie('tell','null',-1);
							require(['jquery','text!./shop/html/shopnull.html','css!./shop/css/shopnull.css'],function($,htmlnull){
								$('#wrap').html(htmlnull);
								var $tell = $("#tell");
								var $pass = $("#pass");
								var $btn = $("#foot div");
								$btn.click(function(){
									cookiejs.setCookie('tell',$tell.val());
									cookiejs.setCookie('pass',$pass.val());
									require(['jquery','text!./mine/mine.html','css!./mine/css/mine.css'],function($,html){
										$('#wrap').html(html);
									});
								})
							});
						})
					});
				}else{
					require(['jquery','text!./shop/html/shopnull.html','css!./shop/css/shopnull.css'],function($,htmlnull){
							$('#wrap').html(htmlnull);
							var $tell = $("#tell");
							var $pass = $("#pass");
							var $btn = $("#foot div");
							$btn.click(function(){
								cookiejs.setCookie('tell',$tell.val());
								cookiejs.setCookie('pass',$pass.val());
								require(['jquery','text!./mine/mine.html','css!./mine/css/mine.css'],function($,html){
									$('#wrap').html(html);
								});
							})
					});
				};
			});
		}
	});
	//启动路由
	var router = new Router();
	//启动路径监听
	Backbone.history.start();
});
